home *** CD-ROM | disk | FTP | other *** search
- Path: gate.net!not-for-mail
- From: feathers@gate.net (Michael Feathers)
- Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
- Subject: Re: Hungarian notation
- Followup-To: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
- Date: 11 Jan 1996 07:44:45 -0500
- Organization: CyberGate, Inc.
- Message-ID: <4d30nt$1d4e@hopi.gate.net>
- References: <30C40F77.53B5@swsbbs.com> <marnoldDJEvtJ.1Lx@netcom.com> <4aleun$jlk@ns.RezoNet.NET> <marnoldDJMDBG.CFz@netcom.com> <4asnkr$7b0@solutions.solon.com> <4ath75$e7i@barnacle.iol.ie> <4b4kij$svt@news.microsoft.com> <dewar.819489496@schonberg> <4bd
- <4cf8hf$8fe@hopi.gate.net> <4cgq30$c0v@weck.brokersys.com> <4cvu68$2jb@macaw.cyberport.com> <4d21og$iab@news.xmission.com> <4d2ok0$69s@beach.and.nl>
- NNTP-Posting-Host: hopi.gate.net
- X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
-
- Jos A. Horsmeier (jos@and.nl) wrote:
- : Just adding domain name prefixes to the names of objects doesn't help
- : anyone; notion of domains should be present in the language itself if
- : one really wants domains, instead of just comparable types as implemented
- : in the C language. Any (decent) C compiler feels perfectly fine if one
- : feeds it something like:
- :
- : #include <stdio.h>
- : #include <string.h>
- :
- : typedef char* empnm_t;
- : typedef char* beernm_t;
- :
- : int main() {
- :
- : empnm_t empnmBoss = "Clinton";
- : beern_t beernMyFavBeer= "Grolsch";
- :
- : if (!strcmp(empnmBoss, beernMyFavBeer))
- : printf("huh?\n");
- :
- : return 0;
- :
- : }
- :
- : The type definitions don't help, the prefixes don't add any clarity
- : and still the program would run fine. If domains would have been implemented
- : in C, both typedefs could have been changed into something like:
- :
- : domain char* empnm_d;
- : domain char* beernm_d;
- :
- : and the compiler would have complained while parsing the arguments of
- : the strcmp() function, i.e. two different domains were compared ...
- :
- : But if domains were implemented in C, we still don't need those explicit
- : prefixes, because the compiler would have warned us about those domain
- : violations, and, like you wrote above: if the semantics change, i.e. the
- : domains change, one still has to change those prefixes accordingly if
- : one used them ...
-
- If you want those domains, you can have them in C++. You easily make
- simple classes that are functionally equivalent but with different
- types to give you the domain safety that you want. You could even
- use inheritance to this end. Make a simple EmployeeName class which
- inherits string and a BeerName class which does also. Assignment won't
- be permitted. As to the use of strcmp, well.. the operator== of
- your classes won't permit that either.
-
- I think that your idea of domains is really a call for a more versatile
- type system, and that is C++.
-
-